package com.loan.exeception;

import com.loan.common.HttpResultEnum;
import com.loan.utils.ResponseResult;
//import com.thx.exception.SmsException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局统一异常处理类
 * @author z
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(value =Exception.class)
    public <T> ResponseResult<T> exceptionHandler(Exception e){
        log.error("服务器出现异常，原因：",e);
        e.printStackTrace();
        return ResponseResult.failed(500,"服务器端异常");
    }


    @ExceptionHandler(value =AppException.class)
    public <T> ResponseResult<T> appExceptionHandler(AppException e){
        log.error("服务器出现异常，原因：",e);
        e.printStackTrace();
        return ResponseResult.failed(e.getCode(),e.getMsg());
    }


/*
    @ExceptionHandler(value = SmsException.class)
    public <T> ResponseResult<T> smsExceptionHandler(SmsException e){
        log.error("短信发送异常，原因：",e);
        e.printStackTrace();
        return ResponseResult.failed(HttpResultEnum.SMS_SEND_FAILED.getCode(),HttpResultEnum.SMS_SEND_FAILED.getMessage());
    }
*/

}